package lx.prac.java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * demos of stream
 * @author LvXin
 * @date 2020/8/26 9:48
 */
public class StreamDemo {
    public static void main(String[] args) {
        test003();
    }

    private static void test003() {
        List<Student> list = new ArrayList<>();
        list.add(new Student("zs",1));
        list.add(new Student("ls",2));
        list.add(new Student("tq",5));
        list.add(new Student("ww",3));
        list.add(new Student("zl",4));

        list.stream().sorted(Comparator.comparing(Student::getAge)).forEach(System.out::println);
    }

    private static void test002() {
        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        long count = strings.stream().filter(String::isEmpty).count();
        System.out.println(count);
    }

    private static void test001() {
        List<Student> list = new ArrayList<>();
        list.add(new Student("zs",1));
        list.add(new Student("ls",2));
        list.add(new Student("tq",5));
        list.add(new Student("ww",3));
        list.add(new Student("zl",4));

        List<Teacher> r = list.stream().map(item -> new Teacher(item.getName(), item.getAge())).collect(Collectors.toList());
        r.forEach(System.out::println);
    }
}
